home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 05 - 1989 / 05.06 Jun 89 / LOC Source / Test Source / ControlLDEF.p < prev    next >
Encoding:
Text File  |  1988-07-27  |  4.0 KB  |  171 lines  |  [TEXT/MPS ]

  1. (*****************************************************
  2. ControlLDEF.p:  List Definition Function for list of
  3.     controls.
  4. *****************************************************)
  5.  
  6. UNIT ControlLDEF;
  7.  
  8. INTERFACE
  9. USES
  10.     {$U MemTypes.p                }    MemTypes,
  11.     {$U QuickDraw.p              }    QuickDraw,
  12.     {$U OSIntf.p                      }    OSIntf,
  13.     {$U ToolIntf.p                    }    ToolIntf,
  14.     {$U PackIntf.p                    }    PackIntf,
  15.     {$U PopMenuIntf.p            }    PopMenuIntf;
  16.  
  17. PROCEDURE    MyLDEF(    lMessage: INTEGER;
  18.                                                        lSelect: Boolean;
  19.                                                    lRect: Rect;
  20.                                                    lCell: Cell;
  21.                                                    lDataOffset,
  22.                                                    lDataLen: INTEGER;
  23.                                                    lHandle: ListHandle);
  24.  
  25. IMPLEMENTATION
  26. CONST
  27.     isVIS                = 255;
  28.     notVIS            =   0;
  29.     
  30. TYPE
  31.     StateStuff = record
  32.             oldPen:        PenState;
  33.             oldPort:        GrafPtr;
  34.             oldClip:        RgnHandle;
  35.             newClip:    RgnHandle;
  36.     end;  { StateStuff }
  37.  
  38. PROCEDURE DrawCell(lSelect: Boolean;
  39.                                                 lRect: Rect;
  40.                                                 lCell: Cell;
  41.                                                 lHandle: ListHandle);
  42.                                                 FORWARD;
  43.     
  44.  
  45.  
  46. (*****************************************************
  47. MyLDEF:  List Definition Function for Controls list.
  48.     Responds to LDrawMsg and lHiliteMsg; ignores
  49.     lInitMsg and lCloseMsg.
  50. *****************************************************)
  51.  
  52. PROCEDURE    MyLDEF(lMessage: INTEGER;
  53.                                                      lSelect: Boolean;
  54.                                                    lRect: Rect;
  55.                                                    lCell: Cell;
  56.                                                    lDataOffset,
  57.                                                    lDataLen: INTEGER;
  58.                                                    lHandle: ListHandle);
  59. BEGIN
  60.     CASE lMessage OF
  61.         lInitMsg:        ;    { no initialization needed    }
  62.         lCloseMsg:    ;    { no deallocation needed    }
  63.         
  64.         lDrawMsg, lHiliteMsg:
  65.             DrawCell(lSelect, lRect, lCell, lHandle);
  66.     END;  { case }
  67. END;  { MyLDEF }
  68.  
  69.  
  70. (*****************************************************
  71. SaveState:  Saves the current drawing environment.
  72. *****************************************************)
  73.  
  74. PROCEDURE SaveState(VAR oldState:  StateStuff; 
  75.                                                     lRect:  Rect;
  76.                                                     lHandle: ListHandle);
  77. BEGIN
  78.     WITH oldState DO BEGIN
  79.         { save the current pen state }
  80.         GetPenState(oldPen);
  81.         
  82.         { save current grafPort, set new grafPort }
  83.         GetPort(oldPort);
  84.         SetPort(lHandle^^.port);
  85.         
  86.         { allocate space for old and new clipping regions }
  87.         oldClip := NewRgn;
  88.         newClip := NewRgn;
  89.         
  90.         { save old clipping region }
  91.         GetClip(oldClip);
  92.         
  93.         { set newClip region to given rectangle }
  94.         RectRgn(newClip, lRect);
  95.         
  96.         { intersection of rect and region }
  97.         SectRgn(oldClip, newClip, newClip);
  98.         
  99.         { set grafPorts' clip region to the intersection }
  100.         SetClip(newClip);
  101.     END;  { with }
  102. END;  { SaveState }
  103.  
  104.  
  105. (*****************************************************
  106. RestoreState:  Restores the current drawing environ-
  107.     ment.
  108. *****************************************************)
  109.  
  110. PROCEDURE RestoreState(oldState:  StateStuff);
  111. BEGIN
  112.     WITH oldState DO BEGIN
  113.         { restore the previous clipping region }
  114.         SetClip(oldClip);
  115.         
  116.         { restore the previous pen state }
  117.         SetPenState(oldPen);
  118.         
  119.         { restore the previous grafPort }
  120.         SetPort(oldPort);
  121.         
  122.         { dispose of the regions' storage }
  123.         DisposeRgn(oldClip);
  124.         DisposeRgn(newClip);
  125.     END;  { with }
  126. END;  { RestoreState }
  127.  
  128.  
  129. (*****************************************************
  130. DrawCell:  Draws the given cell, either selected or
  131.     normal, by drawing the control stored in the cell.
  132. *****************************************************)
  133.  
  134. PROCEDURE DrawCell(lSelect: Boolean;
  135.                                                 lRect: Rect;
  136.                                                 lCell: Cell;
  137.                                                 lHandle: ListHandle);
  138. VAR
  139.     oldState:    StateStuff;
  140.     ch:                ControlHandle;
  141.     dl:                INTEGER;
  142.  
  143. BEGIN
  144.     { save the current drawing environment }
  145.     SaveState(oldState, lRect, lHandle);
  146.     
  147.     { get the cell's data }
  148.     dl := sizeof(Handle);
  149.     LGetCell(@ch, dl, lCell, lHandle);
  150.     
  151.     { update the control's fields }
  152.     with ch^^ do begin
  153.         contrlRect    := lRect;
  154.         contrlVis        := isVIS;
  155.     
  156.         { ensure proper hiliting }
  157.         if (lSelect) then
  158.                 contrlHilite := titlePart
  159.         else begin
  160.                 contrlHilite := 0;
  161.         end;  { if }
  162.     end;  { with ch^^ }
  163.     
  164.     { draw the control }
  165.     Draw1Control(ch);
  166.  
  167.     { restore the previous drawing state }
  168.     RestoreState(oldState);
  169. END;  { DrawCell }
  170.  
  171. END.  { ControlLDEF}